package com.lee.boot.head.first.demo.mongo.dao;

import com.lee.boot.head.first.demo.entity.Student;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author edz
 */
@Repository
public class StudentRepositoryImpl {

    @Autowired
    MongoTemplate mongoTemplate;

    List<Student> listByAge(Integer start, Integer end) {
        Criteria criteria = Criteria.where("age");
        Criteria lte = criteria.gte(start).lte(end);
        List<Student> students = mongoTemplate.find(Query.query(lte), Student.class);
        return students;
    }
}
